<template>
  <a-modal
    v-model="visible"
    :title="this.selectedRowKeysId.length > 0 ? '编辑薪资' : '批量编辑薪资'"
    @ok="handleOk"
    :confirm-loading="confirmLoading"
    @cancel="$emit('update:visible', false)"
  >
    <a-form :form="form" :label-col="{ span: 4 }" :wrapper-col="{ span: 19 }">
      <a-form-item label="薪资">
        <a-input-number
          placeholder="请输入"
          :min="1"
          :max="50000"
          :precision="2"
          v-decorator="['money', { rules: [{ required: true, message: '薪资不能为空' }] }]"
        />
      </a-form-item>
    </a-form>
  </a-modal>
</template>

<script>
import { putUpdateBatch } from "./api";
export default {
  props: {
    visible: {
      type: Boolean,
      default: false
    },
    selectedRowKeysId: {
      type: Array,
      default: () => []
    },
    selectedRowKeys: {
      type: Array,
      default: () => []
    }
  },
  watch: {
    visible(v) {
      if (!v) {
        this.form.resetFields();
      }
    }
  },
  data() {
    return {
      confirmLoading: false,
      form: this.$form.createForm(this, {})
    };
  },
  methods: {
    async onPutUpdateBatch(v) {
      try {
        this.confirmLoading = true;
        await putUpdateBatch(v);
        this.confirmLoading = false;
        this.$notification["success"]({
          message: "操作成功"
        });
        this.$emit("update:visible", false);
        this.$emit("upDate");
      } catch (err) {
        console.log("error log --> ", err);
        this.confirmLoading = false;
      }
    },
    handleOk() {
      // 编辑金额
      this.form.validateFields((err, values) => {
        if (!err) {
          const v = {
            money: values.money,
            ids: this.selectedRowKeysId.length > 0 ? this.selectedRowKeysId : this.selectedRowKeys
          };
          this.onPutUpdateBatch(v);
        }
      });
    }
  }
};
</script>

<style></style>
